package fatworm.concept;

import fatworm.util.Lib;

/**
 *	relational operator
 */
public class RelOp {
	private int relop;
	private RelOp( int relop ){
		this.relop = relop;
	}
	
	/**
	 * @return the reverse part of the operator
	 */
	public RelOp reverse(){
		switch( relop ){
			case O_EQ : return NE;
			case O_NE : return EQ;
			case O_LT : return GE;
			case O_LE : return GT;
			case O_GT : return LE;
			case O_GE : return LT;
			default	  : Lib.assertNotReached(); return null;
		}
	}
	
	/**
	 * get the integer representation of relational operator
	 * @return the integer operation
	 */
	public int getRelop(){
		return relop;
	}
	
	public String toString(){
		return toString( relop );
	}
	
	/** 
	 * get the string representation of relational operator
	 * @param relop	integer representation
	 * @return	string representation
	 */
	public static String toString( int relop ){
		switch( relop ){
			case O_EQ : return "=";
			case O_NE : return "<>";
			case O_LT : return "<";
			case O_LE : return "<=";
			case O_GT : return ">";
			case O_GE : return ">=";
			default	  : Lib.assertNotReached(); return null;
		}
	}
	

	
	public static final int O_EQ = 0 , O_NE = 1 , O_LT = 2 , O_LE = 3 , O_GT = 4 , O_GE = 5; 
	public static final RelOp EQ = new RelOp( O_EQ );
	public static final RelOp NE = new RelOp( O_NE );
	public static final RelOp LT = new RelOp( O_LT );
	public static final RelOp LE = new RelOp( O_LE );
	public static final RelOp GT = new RelOp( O_GT );
	public static final RelOp GE = new RelOp( O_GE );
}
